package com.smile.weather2.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 数据库帮助类
 * Created by smile on 2016/8/24.
 */
public class DBHelper extends SQLiteOpenHelper {

    private final static String DB_NAME = "weather.db";
    private final static int VERSION = 1;
    private final static String SQL_CREATE_CITY = "create table city(" +
            "_id integer primary key autoincrement, " +
            "c_city test not null, " +
            "c_cnty test not null, " +
            "c_id test not null, " +
            "c_lat test, " +
            "c_lon test, " +
            "c_prov test" +
            ")";
//    private final static String SQL_CREATE_WEATHER = "create table weather(" +
//            "_id integer primary key autoincrement, " +
//            "c_city test not null, " +
//            "c_cnty test not null, " +
//            "c_id test not null, " +
//            "c_lat test not null, " +
//            "c_lon test not null, " +
//            "c_prov test" +
//            ")";
    private final static String SQL_DROP_CITY = "drop table if exists city";

    public DBHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(SQL_CREATE_CITY);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        sqLiteDatabase.execSQL(SQL_DROP_CITY);
        sqLiteDatabase.execSQL(SQL_CREATE_CITY);
    }
}
